package demo.fastdfs;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;

import org.csource.common.MyException;
import org.csource.fastdfs.ClientGlobal;
import org.csource.fastdfs.FileInfo;
import org.csource.fastdfs.StorageClient;
import org.csource.fastdfs.StorageServer;
import org.csource.fastdfs.TrackerClient;
import org.csource.fastdfs.TrackerServer;
import org.springframework.core.io.ClassPathResource;

public class FastDfsTest {
	
	public static void main(String[] args) throws FileNotFoundException, IOException, MyException {
		/**/
		ClassPathResource cpr = new ClassPathResource("fdfs_client_old.conf");
		String path = cpr.getClassLoader().getResource("fdfs_client_old.conf").getPath();
		ClientGlobal.init(path);
		TrackerClient trackerClient=new TrackerClient();
		TrackerServer trackerServer = trackerClient.getConnection();
		StorageServer storageServer=null;
		StorageClient storageClient=new StorageClient(trackerServer, storageServer);
		
//		File content = new File("D:\\download1.png");
//        FileInputStream fis = new FileInputStream(content);
//        byte[] file_buff = null;
//        if (fis != null) {
//            int len = fis.available();
//            file_buff = new byte[len];
//            fis.read(file_buff);
//        }
//        
//		String[] upload_file = storageClient.upload_file(file_buff, "png", null);
//		System.out.println(upload_file[0]);
//		System.out.println(upload_file[1]);
		FileInfo get_file_info = storageClient.get_file_info("group1", "M00/00/00/rKgR-lm3uHSAAakDAAAETJDRdnk443.png");
		System.out.println(get_file_info.getSourceIpAddr());
		System.out.println(get_file_info.getCrc32());
		System.out.println(get_file_info.getFileSize());
		System.out.println(get_file_info.getCreateTimestamp());
	}

}
